
import java.util.ArrayList;
import java.util.Scanner;

public class C_1_13_11 {
    public static boolean ifOK(int x) {
        if (x == 1)
            return false;
        if (x == 2)
            return true;
        for (int i = 2; i * i <= x; i++) {
            if (x % i == 0) {
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = 0;
        ArrayList<Integer> list = new ArrayList<>();
        if (n % 2 == 0) {
            d = n / 2;
        } else {
            d = n / 2 + 1;
        }
        int min = (int) Math.pow(10, d-1);
        int max = 10 * min;
        for(int i = min; i<max; i++){
            StringBuffer sb = new StringBuffer(""+i);
            int rev = Integer.parseInt(sb.reverse().toString());
            if(n % 2 == 0){
                if(ifOK(i*max+rev)){
                    list.add(i*max+rev);
                }
            }else{
                if(ifOK(i/10*max+rev)){
                    list.add(i/10*max+rev);
                }
            }
        }
        System.out.println(list.size());
        for(Integer str : list){
            System.out.print(str+" ");

        }

    }
}